﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>厂商信息维护</title>
    <script type="text/javascript" src="../../Script/boot.js"></script>
    <style type="text/css">
        html, body
        {
            font-size: 12px;
            padding: 0;
            margin: 0;
            border: 0;
            height: 100%;
            overflow: hidden;
        }
    </style>
</head>
<body>
    <form id="form1" method="post">
    <fieldset style="border: solid 1px #aaa; padding: 3px; margin: 5px">
        <legend>基本信息</legend>
        <table>
            <tr>
                <td style="width: 70px;">
                    厂商名称：
                    <input name="id" class="mini-hidden" />
                </td>
                <td>
                    <input name="factoryName" class="mini-textbox" required="true" />
                </td>
                <td style="width: 70px;">
                    厂商类别：
                </td>
                <td>
                    <input name="factoryCategoryId" class="mini-combobox" valuefield="id" textfield="factoryCategoryName"
                        url="AjaxService.aspx?method=GetFactoryCategoryList" />
                </td>
            </tr>
            <tr id="superiorFactoryNo1">
                <td style="width: 70px;">
                    上游厂商
                </td>
                <td style="width: 150px;">
                    <input id="superiorFactoryNo" name="superiorFactoryNo" class="mini-buttonedit" onbuttonclick="onButtonSuperFactoryNo" />
                </td>
                <td>
                </td>
                <td>
                </td>
            </tr>
        </table>
    </fieldset>
    <fieldset style="border: solid 1px #aaa; padding: 3px; margin: 5px">
        <legend>地址</legend>
        <table>
            <tr>
                <td style="width: 70px;">
                    省份：
                </td>
                <td>
                    <input id="provnceId" name="provnceId" class="mini-combobox" valuefield="ProvinceID"
                        textfield="ProvinceName" required="true" url="AjaxService.aspx?method=GetProvinceList"
                        onvaluechanged="onProvinceChanged" />
                </td>
                <td style="width: 70px;">
                    城市：&nbsp;
                </td>
                <td>
                    <input id="cityId" name="cityId" class="mini-combobox" valuefield="CityID" textfield="CityName"
                        required="true" onvaluechanged="onCityChanged" />
                </td>
            </tr>
            <tr>
                <td style="width: 70px;">
                    地区：
                </td>
                <td>
                    <input name="districtId" id="districtId" class="mini-combobox" valuefield="DistrictID"
                        textfield="DistrictName" required="true" />
                </td>
                <td style="width: 70px;">
                    地址：
                </td>
                <td>
                    <input name="address" class="mini-textbox" required="true" />
                </td>
            </tr>
        </table>
    </fieldset>
    <fieldset style="border: solid 1px #aaa; padding: 3px; margin: 5px">
        <legend>联系方式</legend>
        <table>
            <tr>
                <td style="width: 70px;">
                    邮编：
                </td>
                <td>
                    <input name="code" class="mini-textbox" vtype="float" />
                </td>
                <td style="width: 70px;">
                    电话：
                </td>
                <td>
                    <input name="telephone" class="mini-textbox" vtype="float" />
                </td>
            </tr>
            <tr>
                <td style="width: 70px;">
                    传真：
                </td>
                <td>
                    <input name="fax" class="mini-textbox" vtype="float" />
                </td>
                <td style="width: 70px;">
                    邮件：
                </td>
                <td>
                    <input name="email" class="mini-textbox" vtype="email" />
                </td>
            </tr>
        </table>
    </fieldset>
    <fieldset style="border: solid 1px #aaa; padding: 3px; margin: 5px">
        <legend>其他</legend>
        <table>
            <tr>
                <td style="width: 70px;">
                    官方网站：
                </td>
                <td>
                    <input name="officalWebSite" class="mini-textbox" vtype="url" />
                </td>
                <td style="width: 70px;">
                    官方网店：
                </td>
                <td>
                    <input name="officalOnlineStore" class="mini-textbox" vtype="url" />
                </td>
            </tr>
        </table>
    </fieldset>
    <div style="text-align: center; padding: 10px;">
        <a class="mini-button" onclick="onOk" style="width: 60px; margin-right: 20px;">确定</a>
        <a class="mini-button" onclick="onCancel" style="width: 60px;">取消</a>
    </div>
    </form>
    <script type="text/javascript">
        mini.parse();
        var form = new mini.Form("form1");
        var provinceCombo = mini.get("provnceId");
        var cityCombo = mini.get("cityId");
        var districtCombo = mini.get("districtId");
        var urlGetRoleString = "../Common/UserSessionTool.aspx?method=ResponseWriteRoleName";
        $.ajax({
            url: urlGetRoleString,
            cache: false,
            success: function (text) {
                alert(text);
                if (text != "超级管理员") {
                    var trSuper = mini.get("superiorFactoryNo");
                    var el = trSuper.getEl();
                    $(el).parent().parent().hide();
                    //mini.get("superiorFactoryNo").hide();

                }

            },
            error: function (jqXHR, textStatus, errorThrown) {
                alert(jqXHR.responseText);
                CloseWindow();
                return false;
            }
        });

        function SaveData() {

            var o = form.getData();

            form.validate();
            if (form.isValid() == false) {
                return;
            }

            var json = mini.encode([o]);
            $.ajax({
                url: "AjaxService.aspx?method=SaveFactory",
                data: { data: json },
                cache: false,
                success: function (text) {
                    //window.close();
                    //CloseWindow("save");
                    mini.alert("操作成功!");
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    alert("error");
                    alert(jqXHR.responseText);
                    CloseWindow();
                }
            });
        }
        function onCancel(e) {
            CloseWindow("cancel");
        }
        //在主页面点击修改按钮时调用-此页面没调用
        function SetData(data) {

            if (data.action == "edit") {
                //跨页面传递的数据对象，克隆后才可以安全使用
                data = mini.clone(data);
                $.ajax({
                    url: "AjaxService.aspx?method=GetFactory&id=" + data.id,
                    cache: false,
                    success: function (text) {
                        var o = mini.decode(text);
                        form.setData(o);
                        onProvinceChanged(e);
                        mini.getbyName("cityId").setValue(o.cityId);
                        onCityChanged2(o.districtId)
                        form.setChanged(false);
                    }
                });
            }
        }

        //保存
        function onOk(e) {
            SaveData();
        }
        //选择省份onchange
        function onProvinceChanged(e) {
            var id = provinceCombo.getValue();

            cityCombo.setValue("");

            var url = "AjaxService.aspx?method=GetCityList&id=" + id
            cityCombo.setUrl(url);

            //cityCombo.select(0);
        }


        //选择城市onchange
        function onCityChanged(e) {
            var id = cityCombo.getValue();

            districtCombo.setValue("");

            var url = "AjaxService.aspx?method=GetDistrictList&id=" + id
            districtCombo.setUrl(url);
            districtCombo.select(0);
        }

        function onCityChanged2(s) {
            var id = cityCombo.getValue();

            districtCombo.setValue("");

            var url = "AjaxService.aspx?method=GetDistrictList&id=" + id
            districtCombo.setUrl(url);
            districtCombo.setValue(s);
        }
        //管理员选择上游经销商
        function onButtonSuperFactoryNo(e) {
            var btnEdit = this;
            mini.open({
                url: bootPATH + "../Manage/Factory/FactorySelectWindow.htm",
                title: "选择列表",
                width: 400,
                height: 350,
                ondestroy: function (action) {

                    //if (action == "close") return false;
                    if (action == "ok") {
                        var iframe = this.getIFrameEl();
                        var data = iframe.contentWindow.GetData();
                        data = mini.clone(data);    //必须
                        if (data) {
                            btnEdit.setValue(data.factoryNo);
                            btnEdit.setText(data.factoryName);
                        }
                    }

                }
            });
        }

    </script>
</body>
</html>
